package controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import util.UrlUtility;

import bizlogic.BookingManager;

import model.BookingDTO;
import model.search.BookingSearchDTO;

@WebServlet("/ViewCurrentBooking")
public class ViewCurrentBookingServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public ViewCurrentBookingServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doShow(request, response);
	}
	
	private void doShow(HttpServletRequest req, HttpServletResponse res) {
		String address = "/WEB-INF/ShowBooking.jsp";
		
		Calendar start = Calendar.getInstance();
		start.set(start.get(Calendar.YEAR), start.get(Calendar.MONTH), 1);
		Date startDate = start.getTime();
		
		Calendar end = Calendar.getInstance();
		end.set(end.get(Calendar.YEAR), end.get(Calendar.MONTH), 1);
		end.add(Calendar.MONTH, 1);
		end.add(Calendar.DATE, -1);
		Date endDate = end.getTime();
		
		BookingSearchDTO bs = new BookingSearchDTO();
		bs.setStartDateFrom(startDate);
		bs.setStartDateTo(endDate);
		bs.setEndDateFrom(startDate);
		bs.setEndDateTo(endDate);
		
		//System.out.println(bs);
		
		BookingManager bm = new BookingManager();
		ArrayList<BookingDTO> list = bm.findBookingByCriteria(bs);
		
		req.setAttribute("booklist", list);
		UrlUtility.forwardPage(req, res, address);
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

}
